<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <div style="height: 47px"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">保 存</multiuse-button>
    </div>
  </div>
</template>
<script>
import { addSave } from '@/api/omSaleP/vehicleParameters/PlanOrderTime/index.js';
import { dictionary } from '@/utils/dictMixin';
export default {
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom(),
      formData: {},
      importVisible: false,
      importsVisible:false
    };
  },

  mixins: [dictionary],

  components: {
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '设置信息'
        },
        {
          type: 'INPUT',
          label: '编号',
          fieldName: 'setNo',
          placeholder: '自动生成',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '设置类型',
          fieldName: 'setType',
          placeholder: '请选择',
          itemList: this.createDictList('2110'),
          initialValue: 21101001,
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'state',
          placeholder: '请选择',
          itemList: this.createDictList('1003'),
          initialValue: 10031001,
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'DATE',
          label: '年月',
          fieldName: 'yearMonth',
          placeholder: '请选择',
          dateType: 'month'
        },
        {
          type: 'RANGE_INPUT_NUMBER',
          label: '日期',
          fieldName: 'begAndendDate',
          placeholder: '请选择',
          initialValue: [],
          min: 1,
          max: 31,
          rules: [
            { required: true, message: '请输入1-31正整数...', trigger: 'blur' },
            {
              required: true,
              validator: (rule, value, callback) => {
                let Rep = /^[1-9]\d*$/;
              
                if (!Rep.test(value[0])) {
                  return callback(new Error('请输入1-31正整数...'));
                }
                if (!Rep.test(value[1])) {
                  return callback(new Error('请输入1-31正整数...'));
                }
                if (parseInt(value[1]) < parseInt(value[0])) {
                  return callback(new Error('结束时间不能大于开始时间...'));
                }
                callback();
              },
              trigger: ['blur']
            }
          ]
        }
        // {
        //   type: 'BREAK_SPACE',
        //   label: '设置信息',
        // },
        //  {
        //   type: 'INPUT',
        //   label: '编号',
        //   fieldName: 'setNo',
        //   placeholder: '自动生成',
        //   disabled: true
        // },
        // {
        //   type: 'SELECT',
        //   label: '设置类型',
        //   fieldName: 'setType',
        //   placeholder: '请选择',
        //   itemList: [{text:"类型一",value:1},{text:"类型二",value:2}],
        // },
        // {
        //   type: 'SELECT',
        //   label: '状态',
        //   fieldName: 'state',
        //   placeholder: '请输入',
        //   itemList: [{text:"状态一",value:1},{text:"状态二",value:2}],
        // },
        // {
        //   type: 'INPUT',
        //   label: '年月',
        //   fieldName: 'years',
        //   placeholder: '请输入',
        // },
        // {
        //   type: 'RANGE_DATE',
        //   label: '日期',
        //   fieldName: 'createDate',
        //   placeholder: '请选择',
        //   initialValue: [],
        //   dateType: 'exactdaterange',
        // }
      ];
    },
    addHandle(type) {
      if (type === 1) {
        this.importVisible = true;
      } else {
      this.importsVisible=true;
      }
    },
    changeHandle(val) {
      debugger
      this.saveData = val;
//       automaticCode: undefined
// createDate: Array(0)
// setType: 2
// state: 1
// years: "123"
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
       this.$refs.from.SUBMIT_FORM();
        
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          let res = await addSave(json);
         
          if (res.resultCode == 200) {
            this.saveData = res.data
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success',
            });
            this.$emit('close', json);
          } else {
            this.saveData = null;
          }
        }
      }
    },
    // 关闭导入弹窗
    importcloseHandler (val) {
  
      this.importVisible = false;

    }
  },
};
</script>
